package birdsnail.springcloud.myselfserviceprovider.dao;

import birdsnail.springcloud.myselfserviceprovider.domain.Employees;
import birdsnail.springcloud.myselfserviceprovider.mapper.EmployeesMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * @author huadong.yang
 */
@Repository
public class EmployeesDao {

    private static final Employees substitute = new Employees();

    private EmployeesMapper employeesMapper;

    @Autowired
    public void setEmployeesMapper(EmployeesMapper employeesMapper) {
        this.employeesMapper = employeesMapper;
    }

    public Employees queryById(Long id) {
        if (id == null) {
            return substitute;
        }
        return Optional.ofNullable(employeesMapper.selectByPrimaryKey(id))
                .orElse(substitute);
    }

}
